package sv.mecca.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import sv.mecca.form.PacientesForm;
import sv.mecca.modelo.OperacionesPacientes;

public class PacientesAction extends DispatchAction{
    OperacionesPacientes oper = new OperacionesPacientes();
    
    public void insertar(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        oper.insertarPacientes((PacientesForm) form);
        request.setAttribute("error", "all.agregar");
        this.listado(mapping, form, request, response);
        }
    public void modificar(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setAttribute("paciente",
            oper.modificarPacientes(request.getParameter("expediente")));
        this.listado(mapping, form, request, response);
        }
    public void actualizar(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        oper.actualizarPacientes((PacientesForm) form, request.getParameter("expediente"));
        request.setAttribute("error", "all.actualizar");
        this.listado(mapping, form, request, response);
        }
    public void eliminar(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        oper.EliminarPacientes(request.getParameter("expediente"));
        request.setAttribute("error", "all.eliminar");
        this.listado(mapping, form, request, response);
        }
    public void listado(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        request.setAttribute("Pacientes", oper.listado());
        request.getRequestDispatcher("/Definiciones/Pacientes.jsp").forward(request, response);
        }
    }